www.gusucode.com > 粒子滤波全套源代码,实现了粒子滤波的全部功能,是粒子滤波提高级程序 > particle filter program/tracker.m

    function Estimate=tracker(x,y,hx,hy,N,first,n,new_sita)
% x=355;y=245;hx=20;hy=20;N=500;n=400;new_sita=0.20;
global v_count;
global matrix;
v_count=512;
matrix=1:1:v_count;   %%%%%maybe it should be changed to global variable


image_boundary_x=int16(720);%int16(700); 
image_boundary_y=int16(576);%int16(550);


Hx=int16(hx);
Hy=int16(hy);
vx=0;
vy=0;
name=num2str(first,'%04.4g');
firstname=[name,'.jpg'];
I=imread(firstname);
[Sample_Set,Sample_probability,Estimate,target_histgram]=initial_2(x,y,Hx,Hy,vx,vy,I,N);

for loop=2:1:n;
    if Estimate(loop-1).prob>=0.05
       k=target_histgram;
       %target_histgram=0.8*k+0.2*Estimate(loop-1).histgram;
       if(loop<100)
         target_histgram=0.90*k+0.10*Estimate(loop-1).histgram;
       elseif(loop<200)
           new_sita=0.25;
         target_histgram=0.99*k+0.01*Estimate(loop-1).histgram;  
       elseif(loop<280)
            new_sita=0.30;
         target_histgram=0.99*k+0.01*Estimate(loop-1).histgram; 
       else
            new_sita=0.30;
         target_histgram=0.99*k+0.01*Estimate(loop-1).histgram; 
       end
    a=num2str(loop+first-1,'%04.4g');
    b=[a,'.jpg'];
    I=imread(b);
                        New_Sample_Set=Select(Sample_Set,Sample_probability,loop,I,N);
               [Sample_Set,after_prop]=Propagation(New_Sample_Set,Hx,Hy,vx,vy,image_boundary_x,image_boundary_y,I,N);
   [Sample_probability,Estimate,vx,vy,TargetPic]=Observe_and_Estimate(Sample_Set,Estimate,Hx,Hy,target_histgram,new_sita,loop,after_prop,I,N);
    else 
        a=0;
        return;
    end
    imshow(TargetPic);
end